﻿using Aker.DevTeam;
using Cikislar;
using DevExpress.XtraGrid.Views.Grid;
using Extensions;
using System;

namespace Aker.Cikislar
{
    public partial class CikisSepet : XForm
    {
        public static AkerDB.CikisLinesDataTable Sepet = new AkerDB.CikisLinesDataTable();

        public static void Init()
        {
            //Sepet.Columns.Add("ProductId", typeof(int));
            Sepet.Columns.Add("Hammadde", typeof(string));
            Sepet.Columns.Add("Thumbnail", typeof(string));
            Sepet.Columns.Add("Artikel", typeof(string));
            Sepet.Columns.Add("Desen", typeof(string));
            Sepet.Columns.Add("Ağırlık", typeof(string));
            Sepet.Columns.Add("Karışım", typeof(string));
            Sepet.Columns.Add("SipNo", typeof(string));
            Sepet.Columns.Add("Müşteri", typeof(string));
            //Sepet.Columns["Aciklama"].SetOrdinal(Sepet.Columns.Count - 1);

            Sepet.Columns["IrsaliyeAciklama"].SetOrdinal(0);
        }


        public static AkerDB.CikisLinesRow YeniCikisLines()
        {
            return Sepet.NewCikisLinesRow();
        }

        public static void SepeteAt(AkerDB.CikisLinesRow cl)
        {
            //TODO
            ////if (!cl.IsProductIdNull() && Data.DB.Product.FindByProductId(cl.ProductId) != null)
            ////    cl.Aciklama = Data.DB.Product.FindByProductId(cl.ProductId).IrsaliyeAciklama;

            if (cl["Hammadde"].ToStringNN() != "")
                cl.IrsaliyeAciklama = cl["Hammadde"].ToStringNN();

            cl.FixNulls();
            Sepet.Rows.Add(cl);
        }

        public CikisSepet()
        {
            InitializeComponent();
        }

        private void CikisSepet_Load(object sender, EventArgs e)
        {
            gv.Init(Sepet);
            gv.MakeReadOnly("Aciklama", "CikilanKG", "CikilanAdet", "CikilanMetre", "SentezKodu");
            gv.Columns["Kartela"].VisibleIndex = 1;
            gv.Columns["SentezKodu"].VisibleIndex = 2;

            gv.OptionsView.ShowViewCaption = false;
            gv.SetCaptions("CikilanKG:Çıkılacak KG", "CikisLinesId:#", "CikilanAdet:Çıkılacak Adet"
                                    , "CikilanMetre:Çıkılacak MT", "IplikId:İplik No", "RollId:Top No", "POrderLinesId:Sip. Satırı No"
                                    , "ElyafId:Elyaf No", "ProductId:Artikel No", "Aciklama:İrsaliye Kod");
            gv.MakeColumnInvisible("CikisId");

            gv.EnableComplexFiltering("Aciklama");

            gv.FormatAsNumber(2, "CikilanKG");
            gv.ValidatingEditor += gv_ValidatingEditor;
            gv.ShowingEditor += gv_ShowingEditor;
            gv.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
            gv.BestFitColumns();
        }

        void gv_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        {

        }

        void gv_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
        {

        }

        void gv_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            //TOSO
        }

        private void btnCik_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gv.EndEditing();
            Cikis.Cik(Sepet, 4);
        }

        private void btnTemizle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Sepet.Clear();
            Sepet.AcceptChanges();
        }

        private void btnYenile_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gv.BestFitColumns();
        }
    }
}